#ifndef CAM_OPENCV_H
#define CAM_OPENCV_H

#pragma once

#define G2L_CAM_INIT "media-ctl -d /dev/media0 --reset && media-ctl -d /dev/media0 -l \"'rzg2l_csi2 10830400.csi2':1->'CRU output':0 [1]\" && media-ctl -d /dev/media0 -V \"'rzg2l_csi2 10830400.csi2':1 [fmt:UYVY8_2X8/800x600 field:none]\" && media-ctl -d /dev/media0 -V \"'ov5645 0-003c':0 [fmt:UYVY8_2X8/800x600 field:none]\""

#include "opencv2/opencv.hpp"
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <linux/v4l2-controls.h>
#include <linux/videodev2.h>
#include <memory>
#include <string.h>
#include <QObject>
#include <vector>
#include <QDebug>
#include <errno.h>
#include <fcntl.h>

#include <sys/ioctl.h>
#include <unistd.h>

enum Board { G2E, G2L, G2M, Unknown };
enum InputOpenCV { cameraInput, imageInput, videoInput };

using namespace cv;

Q_DECLARE_METATYPE(cv::Mat)

class my_opencv : public QObject
{
    Q_OBJECT
public:
    my_opencv(QString cameraLocation, Board board);//create func
    ~my_opencv();

    cv::Mat* getImage(unsigned int iterations);
    void my_colorSpace_change(Mat& image);//change colorspace
    void my_drawing(Mat& image);//在图像中绘制几何图形
    void my_resize(Mat& image);//图像放缩
    void video(Mat& image);
    bool cameraInit();
    bool getCameraOpen();
private:
    void setupCamera();
    void connectCamera();
    void checkCamera();
    int runCommand(std::string command, std::string &stdoutput);

    bool webcamInitialised;
    bool webcamOpened;
    bool usingMipi;
    int connectionAttempts;
    cv::Mat picture;
    cv::VideoCapture *camera;
    std::string webcamName;
    std::string cameraInitialization;
    InputOpenCV inputOpenCV;
};


#endif // CAM_OPENCV_H
